package o;

import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnHoverListener;
import android.view.View.OnLongClickListener;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.core.view.ViewCompat;

@RestrictTo({d.LIBRARY_GROUP})
class cy implements OnLongClickListener, OnHoverListener, OnAttachStateChangeListener {
    private static cy ʻ;
    private static cy ͺ;
    private int ʼ;
    private int ʽ;
    private final View ˊ;
    private final Runnable ˋ = new Runnable(this) {
        final /* synthetic */ cy ˏ;

        {
            this.ˏ = r1;
        }

        public void run() {
            this.ˏ.ˏ(false);
        }
    };
    private final CharSequence ˎ;
    private final int ˏ;
    private final Runnable ॱ = new Runnable(this) {
        final /* synthetic */ cy ˋ;

        {
            this.ˋ = r1;
        }

        public void run() {
            this.ˋ.ˏ();
        }
    };
    private df ॱॱ;
    private boolean ᐝ;

    public static void ˋ(View view, CharSequence charSequence) {
        if (ʻ != null && ʻ.ˊ == view) {
            ˏ(null);
        }
        if (TextUtils.isEmpty(charSequence)) {
            if (ͺ != null && ͺ.ˊ == view) {
                ͺ.ˏ();
            }
            view.setOnLongClickListener(null);
            view.setLongClickable(false);
            view.setOnHoverListener(null);
            return;
        }
        cy cyVar = new cy(view, charSequence);
    }

    private cy(View view, CharSequence charSequence) {
        this.ˊ = view;
        this.ˎ = charSequence;
        this.ˏ = ia.ˏ(ViewConfiguration.get(this.ˊ.getContext()));
        ˎ();
        this.ˊ.setOnLongClickListener(this);
        this.ˊ.setOnHoverListener(this);
    }

    public boolean onLongClick(View view) {
        this.ʽ = view.getWidth() / 2;
        this.ʼ = view.getHeight() / 2;
        ˏ(true);
        return true;
    }

    public boolean onHover(View view, MotionEvent motionEvent) {
        if (this.ॱॱ == null || !this.ᐝ) {
            AccessibilityManager accessibilityManager = (AccessibilityManager) this.ˊ.getContext().getSystemService("accessibility");
            if (!(accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled())) {
                switch (motionEvent.getAction()) {
                    case 7:
                        if (this.ˊ.isEnabled() && this.ॱॱ == null && ˋ(motionEvent)) {
                            ˏ(this);
                            break;
                        }
                    case 10:
                        ˎ();
                        ˏ();
                        break;
                    default:
                        break;
                }
            }
        }
        return false;
    }

    public void onViewAttachedToWindow(View view) {
    }

    public void onViewDetachedFromWindow(View view) {
        ˏ();
    }

    void ˏ(boolean z) {
        if (ViewCompat.ˋˊ(this.ˊ)) {
            long j;
            ˏ(null);
            if (ͺ != null) {
                ͺ.ˏ();
            }
            ͺ = this;
            this.ᐝ = z;
            this.ॱॱ = new df(this.ˊ.getContext());
            this.ॱॱ.ˏ(this.ˊ, this.ʽ, this.ʼ, this.ᐝ, this.ˎ);
            this.ˊ.addOnAttachStateChangeListener(this);
            if (this.ᐝ) {
                j = 2500;
            } else if ((ViewCompat.ʻॱ(this.ˊ) & 1) == 1) {
                j = 3000 - ((long) ViewConfiguration.getLongPressTimeout());
            } else {
                j = 15000 - ((long) ViewConfiguration.getLongPressTimeout());
            }
            this.ˊ.removeCallbacks(this.ॱ);
            this.ˊ.postDelayed(this.ॱ, j);
        }
    }

    void ˏ() {
        if (ͺ == this) {
            ͺ = null;
            if (this.ॱॱ != null) {
                this.ॱॱ.ˏ();
                this.ॱॱ = null;
                ˎ();
                this.ˊ.removeOnAttachStateChangeListener(this);
            } else {
                Log.e("TooltipCompatHandler", "sActiveHandler.mPopup == null");
            }
        }
        if (ʻ == this) {
            ˏ(null);
        }
        this.ˊ.removeCallbacks(this.ॱ);
    }

    private static void ˏ(cy cyVar) {
        if (ʻ != null) {
            ʻ.ˋ();
        }
        ʻ = cyVar;
        if (ʻ != null) {
            ʻ.ˊ();
        }
    }

    private void ˊ() {
        this.ˊ.postDelayed(this.ˋ, (long) ViewConfiguration.getLongPressTimeout());
    }

    private void ˋ() {
        this.ˊ.removeCallbacks(this.ˋ);
    }

    private boolean ˋ(MotionEvent motionEvent) {
        int x = (int) motionEvent.getX();
        int y = (int) motionEvent.getY();
        if (Math.abs(x - this.ʽ) <= this.ˏ && Math.abs(y - this.ʼ) <= this.ˏ) {
            return false;
        }
        this.ʽ = x;
        this.ʼ = y;
        return true;
    }

    private void ˎ() {
        this.ʽ = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        this.ʼ = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
    }
}
